define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'store/category/index' + location.search,
                    add_url: 'store/category/add',
                    edit_url: 'store/category/edit',
                    del_url: 'store/category/del',
                    multi_url: 'store/category/multi',
                    import_url: 'store/category/import',
                    table: 'wanlshop_category',
                }
            });

            var table = $("#table");

            $(".btn-add").data("area", ["100%", "100%"]);

            //当内容渲染完成给编辑按钮添加`data-area`属性
            table.on('post-body.bs.table', function (e, settings, json, xhr) {
                    $(".btn-editone").data("area", ["40%", "40%"]);
                    $(".btn-add").data("area", ["40%", "40%"]);
             });

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                       // {field: 'pid', title: __('Pid')},
                       // {field: 'code', title: __('Code'), operate: 'LIKE'},
                       {field: 'category', title: __('Category'), searchList: {"0":__('Category 0'),"1":__('Category 1'),"2":__('Category 2'),"3":__('Category 3')}, formatter: Table.api.formatter.normal},
                       {field: 'publishing_platform', title: __('发布平台'), searchList: {"0":__('收银台'),"1":__('供货端'),"2":__('不限平台')}, formatter: Table.api.formatter.normal},
                       // {field: 'isnav', title: __('Isnav'), searchList: {"1":__('Yes'),"0":__('No')}, formatter: Table.api.formatter.normal},
                       // {field: 'weigh', title: __('Weigh'), operate: false},
                       {field: 'status', title: __('Status'), searchList: {"normal":__('Normal'),"hidden":__('Hidden')}, formatter: Table.api.formatter.status},
                      
                       // {field: 'type', title: __('Type'), searchList: {"article":__('Article'),"goods":__('Goods')}, formatter: Table.api.formatter.normal},
                        
                        // {field: 'name_spacer', title: __('Name_spacer'), operate: 'LIKE'},
                        // {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        // {field: 'flag', title: __('Flag'), searchList: {"hot":__('Hot'),"new":__('New'),"recommend":__('Recommend')}, operate:'FIND_IN_SET', formatter: Table.api.formatter.label},
                        // {field: 'isnav', title: __('Isnav'), searchList: {"1":__('Yes'),"0":__('No')}, formatter: Table.api.formatter.normal},
                        // {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'weigh', title: __('Weigh'), operate: false},
                        // {field: 'status', title: __('Status'), searchList: {"normal":__('Normal'),"hidden":__('Hidden')}, formatter: Table.api.formatter.status},
                        // {field: 'code', title: __('Code'), operate: 'LIKE'},
                       
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
